package com.huluobo.a2307monthdemo2.login

import androidx.lifecycle.MutableLiveData
import com.huluobo.lib_base.bean.Money
import com.huluobo.lib_base.bean.UserBean
import com.huluobo.lib_base.db.DouYinDatabase
import com.huluobo.lib_base.mvvm.BaseViewModel
import com.huluobo.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 *  Created by LC on 2025/10/8.
 */
@HiltViewModel
class LoginViewModel @Inject constructor(private val apiService: ApiService, private val db: DouYinDatabase) :
    BaseViewModel() {
    val loginSuccess by lazy { MutableLiveData<UserBean>() }
    fun login(map: Map<String, Any>) {
        executeNetwork(
            { apiService.login(mapToJson(map)) },
            loginSuccess::postValue
        )
    }

    val registerSuccess by lazy { MutableLiveData<UserBean>() }
    fun register(map: Map<String, Any>) {
        executeNetwork(
            { apiService.register(mapToJson(map)) },
            registerSuccess::postValue
        )
    }

    val insertMoneySuccess by lazy { MutableLiveData<String>() }
    fun insertMoney(money: Money) {
        executeDb(
            {
                db.getMoneyDao().insertMoney(money)
                "添加余额成功"
            },
            insertMoneySuccess::postValue
        )
    }
}